﻿/***
    This file is part of Qasparov.

    Qasparov is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Qasparov is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Qasparov. If not, see <http://www.gnu.org/licenses/>.

 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Com.Oxilly.Qsb.Core.SDK.API
{
    /// <summary>
    /// A QsbMessage is used to send a message to QApps, this does not cause the QApp to become active
    /// QsbMessages are intended to send information on how to behave. for example configuration information.
    /// A QsbMessage can be either come from a QApp, the Q Service Bus itself, or can be injected by an external 
    /// Application throug the WCF Service. External applications can receive QsbMessages
    /// </summary>
    public class QsbMessage
    {
        private const int MAX_COUNTER = 100;
        private static Int32 counter; 
        private int number;

        public QsbMessage()
        {
            lock (typeof(QsbMessage))
            {
                this.number = NextNumber();
            }
        }

        private static int NextNumber()
        {
            if (counter++ == MAX_COUNTER)
            {
                counter = 0;
            }
            return counter;
        }
        
        public String MessageType { get; set; }
        public String MessageSender { get; set; }
        public String Description { get; set; }

        private SortedList<String, String> messageAttributes = new SortedList<string, string>();
 
        
        public SortedList<String, String> MessageAttributes
        {
            get {
            return this.messageAttributes; 
        } }

        public Int32 Number { get { return this.number; } }
    }
}
